var sdap_validate_request_file_type_error='';
var sdap_validate_request_project_error='';
var sdap_validate_request_problem_name_error='';
var sdap_validate_request_problem_description_error='';
var sdap_validate_request_date_detect_error='';
var sdap_validate_request_date_expect_error='';
var sdap_validate_request_message_error='';

function isValidDateDetect(name)
{
    var result=false;
	var y=document.getElementById(name+'_y').value;
	var m=document.getElementById(name+'_m').value;
	var d=document.getElementById(name+'_d').value;
    if (validateDate(y, m, d))
    {
        var date=new Date(y, m-1, d, 0, 0, 0, 0);
        var now=new Date();
        if (now > date)
        {
            result=true;
        }
    }
    return result;
}

function isValidDateExpect(name)
{
    var result=false;
	var y=document.getElementById(name+'_y').value;
	var m=document.getElementById(name+'_m').value;
	var d=document.getElementById(name+'_d').value;
    if (validateDate(y, m, d))
    {
        var date=new Date(y, m-1, d, 23, 59, 59, 999);
        var now=new Date();
        if (now <= date)
        {
            result=true;
        }
    }
    return result;
}

function isValidFile(name)
{
    var result=true;
	var file=document.getElementById(name).value;
	if(file)
    {
		var reg=/^(.*)(.)(pdf|doc|rtf|xls|odt|ods|jpg|jpeg|gif|png|tar\.bz2|gz|z|zip|rar|sfx|001|002|003|004|005|tar|bz2|exe|log|txt|trc|prn|jrn|odt|rpm)$/i;
		if (!reg.test(file))
        {
             result=false;
        }
	}
    return result;
}

function Validate(submit)
{
    var result=false;
    switch(submit.name)
    {
        case 'sendmessage':
            var message=document.getElementById('new_message').value;
            if ('' == message)
            {
                alert(sdap_validate_request_message_error);
            }
            else
            {
                if (isValidFile('file'))
                {
                    result=true;
                }
                else
                {
                    alert(sdap_validate_request_file_type_error);
                }
            }
            break;
        case 'changedateexpect':
            if (isValidDateExpect('date_expect'))
            {
                result=true;
            }
            else
            {
                alert(sdap_validate_request_date_expect_error);
            }
            break;
        case 'register':
            var project=document.getElementById('project').value;
            var problem_name=document.getElementById('problem_name').value;
            var problem_description=document.getElementById('problem_description').value;
            if ('' == project)
            {
                alert(sdap_validate_request_project_error);
            }
            else if ('' == problem_name)
            {
                alert(sdap_validate_request_problem_name_error);
            }
            else if ('' == problem_description)
            {
                alert(sdap_validate_request_problem_description_error);
            }
            else
            {
                var isFile=false;
                var isDateDetect=false;
                if (isValidDateDetect('date_detect'))
                {
                    isDateDetect=true;
                }
                else
                {
                    alert(sdap_validate_request_date_detect_error);
                }
                if (isValidFile('file'))
                {
                    isFile=true;
                }
                else
                {
                    alert(sdap_validate_request_file_type_error);
                }
                if (isDateDetect && isFile)
                {
                    result=true;
                }
            }
            break;
    }
    return result;
}